|
|
|
|
|
|
|
plus the If statements and overhead for the For loops, it should be no big surprise that this may take a while. Bigger images with bigger kernels will take even longer. |
|
|
|
|
|
|
|
|
Visual Basic does not have a statement that initializes the values in an array of single precision values. That makes initializing large kernels somewhat awkward. The program must include a line to initialize each coefficient in the array as shown in the following code. |
|
|
|
 |
|
|
|
|
Dim kernel(-2 To 2) As Single
kernel(-2, -2) = 1 / 20
kernel(-2, -1) = 1 / 15
kernel(-2, 0) = 1 / 10
: |
|
|
|
|
|
|
|
|
On the other hand, Visual Basic's Array statement creates an array of variants using the values it is passed. The items in the array can be almost anything, including single precision numbers, strings, or other variants that may themselves be arrays. |
|
|
|
|
|
|
|
|
You can use the Array statement to initialize a variant array containing variant arrays that hold kernel coefficients. You can then use the VariantToArray subroutine shown in the following code to copy the coefficients into a normal, two-dimensional array of singles. |
|
|
|
 |
|
|
|
|
' Copy kernel entries from a variant array of
' variant arrays into a normal array. Private Sub VariantToArray(ByVal var As Variant, _
ByRef arr() As Single)
Dim bound As Integer
Dim i As Integer
Dim j As Integer
bound = UBound(var) \ 2
ReDim arr(-bound To bound, -bound To bound)
For i = -bound To bound
For j = -bound To bound
arr(i, j) = var(i + bound)(j + bound)
Next j
Next i
End Sub |
|
|
|
|
|
|
|
|
Program Filter uses this subroutine to initialize many of its kernels. For example, the following code shows how the program initializes the kernel for an embossing filter. |
|
|
|
 |
|
|
|
|
VariantToArray Array( _
Array(1, 0, 0), _
Array(0, 0, 0), _
Array(0, 0, -1)), _
TheKernel |
|
|
|
|
|